<template>
  <n-modal
    v-model:show="modelValue.toDelete"
    :mask-closable="false"
    preset="dialog"
    title="确认"
    content="你确认"
    positive-text="确认"
    negative-text="算了"
    @positive-click="onPositiveClick"
    @negative-click="modelValue.toDelete = false"
  />
</template>

<script lang="ts" setup generic="T extends object & { toEdit: boolean,toDelete:boolean,toDealRowId: number|undefined}">
import UseLifeModel from "@pinias/UseLifeModel";
import UseSurfaceSetting from "@pinias/UseSurfaceSetting";
import pinia from "@pinias/pinia";
import { NModal, useMessage } from "naive-ui";
import { computed } from "vue";

// 全局数据
const { getLifeModel } = UseLifeModel(pinia);
const lifeModel = getLifeModel();
const { getSurfaceSetting } = UseSurfaceSetting(pinia);
const surfaceSetting = getSurfaceSetting();
// 父组件数据
const props = defineProps<{ modelValue: T }>();
const emit = defineEmits(["update:modelValue"]);
const modelValue = computed({
  get: () => props.modelValue,
  set: val => emit("update:modelValue", val),
});
const message = useMessage();
const onPositiveClick = () => {
  //message.success("Submit");
  // console.log(toDealRow);
  const id = modelValue.value.toDealRowId;
  const lifeModeData = lifeModel.getLifeModelDataById(id);
  if (lifeModeData !== undefined && lifeModeData.timeManageList.length > 0) {
    message.error("存在时间事项，不可删除");
    return;
  }
  // lifeModel.tosaveList = lifeModel.tosaveList.filter(item => item !== id)
  lifeModel.data = lifeModel.data.filter(item => item.id !== id);
  lifeModel.list = lifeModel.list.filter(item => item !== id);
  // tableData.value = tableData.value.filter(item => item.id !== id);
  modelValue.value.toDelete = false;
  surfaceSetting.LifeModelListKey = new Date().getTime();
};
</script>
